home *** CD-ROM | disk | FTP | other *** search
/ Tech Win 1995 November / CD [TECH_B].bin / tech_b / delphi / trial / disk4 / doc.pak / OUTLINE.INT < prev    next >
Encoding:
Text File  |  1995-08-08  |  9.6 KB  |  258 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Delphi Visual Component Library                 }
  4. {                                                       }
  5. {       Copyright (c) 1995 Borland International        }
  6. {                                                       }
  7. {*******************************************************}
  8.  
  9. unit Outline;
  10.  
  11. interface
  12.  
  13. {$R OUTLINE}
  14.  
  15. uses WinTypes, WinProcs, Messages, Forms, Classes, Graphics,
  16.   Menus, StdCtrls, Grids, Controls, SysUtils;
  17.  
  18. type
  19.   OutlineError = class(TObject); { Raised by GetNodeAtIndex }
  20.   EOutlineError = class(Exception);
  21.   TOutlineNodeCompare = (ocLess, ocSame, ocGreater, ocInvalid);
  22.   TAttachMode = (oaAdd, oaAddChild, oaInsert);
  23.   TChangeRange = -1..1;
  24.   TCustomOutline = class;
  25.  
  26. { TOutlineNode }
  27.  
  28. { The TOutlineNode is an encapsulation of an outliner item.  Access
  29.   to a TOutlineNode is via the container class TOutline.  Each
  30.   TOutlineNode contains user defined text and data.
  31.   An item is also capable of containing up to 16368 sub-items.
  32.   TOutlineNodes are also persistent.
  33.  
  34.   A TOutlineNode item can be interrogated about its current state :
  35.     Expanded
  36.       Whether the node is open or closed.
  37.     Index
  38.       The current Index of the node.  This changes as items are inserted and
  39.       deleted.  The index will range from 1..n
  40.     Level
  41.       The current depth of the node with 1 being the top level
  42.     HasItems
  43.       Whether the item contains items
  44.     IsVisible
  45.       Whether the item is capable of being displayed. This value is only
  46.       True if all its parent items are visible
  47.     TopItem
  48.       Obtains the parent of the item that resides at level 1
  49.     FullPath
  50.       Returns the fully qualified name of the item starting from its
  51.       level 1 parent.  Each item is separated by the separator string
  52.       specified in the TOutline Container
  53.     Text
  54.       Used to set and get the items text value
  55.     Data
  56.       Used to get and set the items data }
  57.  
  58.   TOutlineNode = class(TPersistent)
  59.   protected
  60.     constructor Create(AOwner: TCustomOutline);
  61.     destructor Destroy; override;
  62.     function GetVisibleNode(TargetCount: LongInt): TOutlineNode;
  63.     function AddNode(Value: TOutlineNode): LongInt;
  64.     function InsertNode(Index: LongInt; Value: TOutlineNode): LongInt;
  65.     function GetNodeAtIndex(TargetIndex: LongInt): TOutlineNode;
  66.     function GetDataItem(Value: Pointer): LongInt;
  67.     function GetTextItem(const Value: string): LongInt;
  68.     function HasAsParent(Value: TOutlineNode): Boolean;
  69.     function GetRowOfNode(TargetNode: TOutlineNode;
  70.       var RowCount: Longint): Boolean;
  71.     procedure Remove(Value: TOutlineNode);
  72.     procedure WriteNode(Buffer: PChar; Stream: TStream);
  73.     property Outline: TCustomOutline;
  74.     property List: TList;
  75.     property ExpandCount: LongInt;
  76.     property Items[Index: LongInt]: TOutlineNode; default;
  77.   public
  78.     procedure ChangeLevelBy(Value: TChangeRange);
  79.     procedure Collapse;
  80.     procedure Expand;
  81.     procedure FullExpand;
  82.     function GetDisplayWidth: Integer;
  83.     function GetFirstChild: LongInt;
  84.     function GetLastChild: LongInt;
  85.     function GetNextChild(Value: LongInt): LongInt;
  86.     function GetPrevChild(Value: LongInt): LongInt;
  87.     procedure MoveTo(Destination: LongInt; AttachMode: TAttachMode);
  88.     property Parent: TOutlineNode;
  89.     property Expanded: Boolean;
  90.     property Text: string;
  91.     property Data: Pointer;
  92.     property Index: LongInt;
  93.     property Level: Cardinal;
  94.     property HasItems: Boolean;
  95.     property IsVisible: Boolean;
  96.     property TopItem: Longint;
  97.     property FullPath: string;
  98.   end;
  99.  
  100. { TCustomOutline }
  101.  
  102. { The TCustomOutline object is a container class for TOutlineNodes.
  103.   All TOutlineNodes contained within a TOutline are presented
  104.   to the user as a flat array of TOutlineNodes, with a parent
  105.   TOutlineNode containing an index value that is one less than
  106.   its first child (if it has any children).
  107.  
  108.   Interaction with a TOutlineNode is typically accomplished through
  109.   the TCustomOutline using the following properties:
  110.     CurItem
  111.       Reads and writes the current item
  112.     ItemCount
  113.       Returns the total number of TOutlineNodes with the TCustomOutline.
  114.       Note this can be computationally expensive as all indexes will
  115.       be forced to be updated!!
  116.     Items
  117.       Allows Linear indexing into the hierarchical list of TOutlineNodes
  118.     SelectedItem
  119.       Returns the Index of the TOutlineNode which has the focus or 0 if
  120.       no TOutlineNode has been selected
  121.  
  122.   The TCustomOutline has a number of properties which will affect all
  123.   TOutlineNodes owned by the TCustomOutline:
  124.     OutlineStyle
  125.       Sets the visual style of the outliner
  126.     ItemSeparator
  127.       Sets the delimiting string for all TOutlineNodes
  128.     PicturePlus, PictureMinus, PictureOpen, PictureClosed, PictureLeaf
  129.       Sets custom bitmaps for these items }
  130.  
  131.   TBitmapArrayRange = 0..4;
  132.   EOutlineChange = procedure (Sender: TObject; Index: LongInt) of object;
  133.   TOutlineStyle = (osText, osPlusMinusText, osPictureText,
  134.     osPlusMinusPictureText, osTreeText, osTreePictureText);
  135.   TOutlineBitmap = (obPlus, obMinus, obOpen, obClose, obLeaf);
  136.   TOutlineBitmaps = set of TOutlineBitmap;
  137.   TBitmapArray = array[TBitmapArrayRange] of TBitmap;
  138.   TOutlineType = (otStandard, otOwnerDraw);
  139.   TOutlineOption = (ooDrawTreeRoot, ooDrawFocusRect, ooStretchBitmaps);
  140.   TOutlineOptions = set of TOutlineOption;
  141.  
  142.  
  143.   TCustomOutline = class(TCustomGrid)
  144.   protected
  145.     procedure Loaded; override;
  146.     procedure Click; override;
  147.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  148.     procedure KeyPress(var Key: Char); override;
  149.     function SetGoodIndex(Value: TOutlineNode): TOutlineNode;
  150.     procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
  151.       AState: TGridDrawState); override;
  152.     procedure DblClick; override;
  153.     procedure SetLevel (Node: TOutlineNode; CurLevel, NewLevel: Cardinal);
  154.     function BadIndex(Value: TOutlineNode): Boolean;
  155.     procedure DeleteNode(Node: TOutlineNode; CurIndex: LongInt);
  156.     procedure Expand(Index: LongInt); dynamic;
  157.     procedure Collapse(Index: LongInt); dynamic;
  158.     procedure DefineProperties(Filer: TFiler); override;
  159.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  160.       X, Y: Integer); override;
  161.     procedure Move(Destination, Source: LongInt; AttachMode: TAttachMode);
  162.     procedure SetDisplayWidth(Value: Integer);
  163.     property Lines: TStrings;
  164.     property OutlineStyle: TOutlineStyle default osTreePictureText;
  165.     property OnExpand: EOutlineChange;
  166.     property OnCollapse: EOutlineChange;
  167.     property Options: TOutlineOptions default [ooDrawTreeRoot, ooDrawFocusRect];
  168.     property Style: TOutlineType default otStandard;
  169.     property ItemHeight: Integer;
  170.     property OnDrawItem: TDrawItemEvent;
  171.     property ItemSeparator: string;
  172.     property PicturePlus: TBitmap index 0;
  173.     property PictureMinus: TBitmap index 1;
  174.     property PictureOpen: TBitmap index 2;
  175.     property PictureClosed: TBitmap index 3;
  176.     property PictureLeaf: TBitmap index 4;
  177.   public
  178.     constructor Create(AOwner: TComponent); override;
  179.     destructor Destroy; override;
  180.     function Add(Index: LongInt; const Text: string): LongInt;
  181.     function AddChild(Index: LongInt; const Text: string): LongInt;
  182.     function AddChildObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
  183.     function AddObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
  184.     function Insert(Index: LongInt; const Text: string): LongInt;
  185.     function InsertObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
  186.     procedure Delete(Index: LongInt);
  187.     function GetDataItem(Value: Pointer): Longint;
  188.     function GetNodeDisplayWidth(Node: TOutlineNode): Integer;
  189.     function GetTextItem(const Value: string): Longint;
  190.     function GetItem(X, Y: Integer): LongInt;
  191.     procedure FullExpand;
  192.     procedure FullCollapse;
  193.     procedure LoadFromFile(const FileName: string);
  194.     procedure LoadFromStream(Stream: TStream);
  195.     procedure SaveToFile(const FileName: string);
  196.     procedure SaveToStream(Stream: TStream);
  197.     procedure BeginUpdate;
  198.     procedure EndUpdate;
  199.     procedure SetUpdateState(Value: Boolean);
  200.     procedure Clear;
  201.     property ItemCount: LongInt;
  202.     property Items[Index: LongInt]: TOutlineNode; default;
  203.     property SelectedItem: Longint;
  204.     property Row;
  205.     property Canvas;
  206.   end;
  207.  
  208.   TOutline = class(TCustomOutline)
  209.   published
  210.     property Lines;
  211.     property OutlineStyle;
  212.     property OnExpand;
  213.     property OnCollapse;
  214.     property Options;
  215.     property Style;
  216.     property ItemHeight;
  217.     property OnDrawItem;
  218.     property Align;
  219.     property Enabled;
  220.     property Font;
  221.     property Color;
  222.     property ParentColor;
  223.     property ParentCtl3D;
  224.     property Ctl3D;
  225.     property TabOrder;
  226.     property TabStop;
  227.     property Visible;
  228.     property OnClick;
  229.     property DragMode;
  230.     property DragCursor;
  231.     property OnDragDrop;
  232.     property OnDragOver;
  233.     property OnEndDrag;
  234.     property OnEnter;
  235.     property OnExit;
  236.     property OnMouseDown;
  237.     property OnMouseMove;
  238.     property OnMouseUp;
  239.     property OnDblClick;
  240.     property OnKeyDown;
  241.     property OnKeyPress;
  242.     property OnKeyUp;
  243.     property BorderStyle;
  244.     property ItemSeparator;
  245.     property PicturePlus;
  246.     property PictureMinus;
  247.     property PictureOpen;
  248.     property PictureClosed;
  249.     property PictureLeaf;
  250.     property ParentFont;
  251.     property ParentShowHint;
  252.     property ShowHint;
  253.     property PopupMenu;
  254.     property ScrollBars;
  255.   end;
  256.  
  257. implementation
  258.